# MAPLE ASSIGNMENT 8
# SOLVING SYSTEMS OF LINEAR EQUATIONS
# The exercise here is to see how Maple preforms when asked to solve a
# large system of linear equations. Please feel free to change the
# numbers in the matrices in any way you like.
> with(linalg):
Warning, new definition for norm
Warning, new definition for trace
> A:=matrix(6,6,[1,0,-1,1,5,7,3,3,9,9,3,3,7,5,1,-1,0,1,1,0,-1,3,6,21,3,3
> ,9,1,0,-1,1,5,7,3,3,9]);

                      [1    0    -1     1    5     7]
                      [                             ]
                      [3    3     9     9    3     3]
                      [                             ]
                      [7    5     1    -1    0     1]
                 A := [                             ]
                      [1    0    -1     3    6    21]
                      [                             ]
                      [3    3     9     1    0    -1]
                      [                             ]
                      [1    5     7     3    3     9]

> det(A);

                                106272

# Even though the vector of constants appears on the screen as a row
# vector, in Maple it is treated as a column vector if that is what the
# context calls for.
> b:=vector([1,3,0,-2,4,5]);

                       b := [1, 3, 0, -2, 4, 5]

> x:=linsolve(A,b);

                     [-397  242  305  -221  283  -167]
                x := [----, ---, ---, ----, ---, ----]
                     [738   369  738  738   369  738 ]

> evalm(A&*x);

                         [1, 3, 0, -2, 4, 5]

> evalm(x&*A);

                 [250  640  1534  1528  -1180  -3866]
                 [---, ---, ----, ----, -----, -----]
                 [41   123  123   369    369    369 ]

> x1:=A^(-1)&*b;

                           x1 := (1/A) &* b

> evalm(");

                  [-397  242  305  -221  283  -167]
                  [----, ---, ---, ----, ---, ----]
                  [738   369  738  738   369  738 ]

> evalm(x1-x);

                          [0, 0, 0, 0, 0, 0]

# Maple uses the Gauss-Jordan method discussed in the text to do the
# calculations above. This means that as long as the entries in A & b
# are integers or rational numbers (integer/integer) the answer is given
# as rational numbers and so it is the exact answer. The method does not
# introduce rounding errors into the calculation.
# For fun you can do some plots of matrices. I suggest redrawing the
# plot so the axes are framed and the style is patch + contour.     
> with(plots):
> matrixplot(A,heights=histogram);

> H:=hilbert(8);

       [ 1     1/2    1/3     1/4     1/5     1/6     1/7     1/8 ]
       [                                                          ]
       [1/2    1/3    1/4     1/5     1/6     1/7     1/8     1/9 ]
       [                                                          ]
       [1/3    1/4    1/5     1/6     1/7     1/8     1/9     1/10]
       [                                                          ]
       [1/4    1/5    1/6     1/7     1/8     1/9     1/10    1/11]
  H := [                                                          ]
       [1/5    1/6    1/7     1/8     1/9     1/10    1/11    1/12]
       [                                                          ]
       [1/6    1/7    1/8     1/9     1/10    1/11    1/12    1/13]
       [                                                          ]
       [1/7    1/8    1/9     1/10    1/11    1/12    1/13    1/14]
       [                                                          ]
       [1/8    1/9    1/10    1/11    1/12    1/13    1/14    1/15]

> T:=toeplitz([1,2,3,4,-4,-3,-2,-1]);

              [ 1     2     3     4    -4    -3    -2    -1]
              [                                            ]
              [ 2     1     2     3     4    -4    -3    -2]
              [                                            ]
              [ 3     2     1     2     3     4    -4    -3]
              [                                            ]
              [ 4     3     2     1     2     3     4    -4]
         T := [                                            ]
              [-4     4     3     2     1     2     3     4]
              [                                            ]
              [-3    -4     4     3     2     1     2     3]
              [                                            ]
              [-2    -3    -4     4     3     2     1     2]
              [                                            ]
              [-1    -2    -3    -4     4     3     2     1]

> matrixplot(H+T,heights=histogram);

> 
